package com.library.role.service;

import com.framework.Page;
import com.library.entity.Role;
import com.library.role.dao.RoleDaoImpl;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

@Service
@Transactional(readOnly=false)
public class RoleServiceImpl {
	
	@Resource
	private RoleDaoImpl roleDaoImpl;
	
	public void addRole(Role role){
		this.roleDaoImpl.saveRole(role);
	}

	@Transactional(readOnly=true)
	public Role getRole(int roleId){
		return this.roleDaoImpl.getRole(roleId);
	}
	
	public void editRole(Role role){
		this.roleDaoImpl.updateRole(role);
	}
	
	public void deleteRole(int roleId){
		Role role = this.getRole(roleId);
		this.roleDaoImpl.deleteRole(role);
	}

	/*删除多个角色*/
	public void deleteRoleGroup(int[] roles){
		Role r = null;
		for(int i = 0;i < roles.length;++i){
			r = this.getRole(roles[i]);
			this.roleDaoImpl.deleteRole(r);
		}

	}

	@Transactional(readOnly=true)
	/*查找全部角色*/
	public List<Role> getAllRoles(){
		return this.roleDaoImpl.getAll();
	}

	@Transactional(readOnly=true)
	/*查找全部角色*/
	public Page<Role> getAllRoles(int pageNum, int pageSize, Map paramsMap){
		return this.roleDaoImpl.findPageByProperty(pageNum,pageSize,paramsMap);
	}
}
